package com.study.service;

import brave.Tracer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 展示 sleuth 生成的相关的跟踪信息
 */
@Slf4j
@Service
public class SleuthTraceInfoService {

    //跟踪对象
    private final Tracer tracer;

    public SleuthTraceInfoService(Tracer tracer){
        this.tracer = tracer;
    }

    //打印当前的跟踪信息到日志中
    public void logCurrentTraceInfo(){
        log.info("sleuth trace id: [{}]",tracer.currentSpan().context().traceId());
        log.info("sleuth span id: [{}]",tracer.currentSpan().context().spanId());
    }

}
